package com.sleepfish.activiti.mapper;

import com.sleepfish.activiti.domain.BpmTaskAssignRule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sleepfish.activiti.util.BaseMapperX;
import com.sleepfish.activiti.util.QueryWrapperX;
import org.springframework.lang.Nullable;

import java.util.List;

/**
 * <p>
 * Bpm 任务规则表 Mapper 接口
 * </p>
 *
 * @author xiaochao
 * @since 2022-03-13
 */
public interface BpmTaskAssignRuleMapper extends BaseMapperX<BpmTaskAssignRule> {
    default List<BpmTaskAssignRule> selectListByProcessDefinitionId(String processDefinitionId,
                                                                      @Nullable String taskDefinitionKey) {
        return selectList(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("process_definition_id", processDefinitionId)
                .eqIfPresent("task_definition_key", taskDefinitionKey));
    }

    default List<BpmTaskAssignRule> selectListByModelId(String modelId) {
        return selectList(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .eq("process_definition_id", BpmTaskAssignRule.PROCESS_DEFINITION_ID_NULL));
    }

    default BpmTaskAssignRule selectListByModelIdAndTaskDefinitionKey(String modelId,
                                                                        String taskDefinitionKey) {
        return selectOne(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .eq("process_definition_id", BpmTaskAssignRule.PROCESS_DEFINITION_ID_NULL)
                .eq("task_definition_key", taskDefinitionKey));
    }
}
